package me.duwl;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class UserManager {
	private static  SqlSessionFactory sqlMapper=null;
	static {
		try {
			Reader reader = Resources
					.getResourceAsReader("me/duwl/SqlMapConfig.xml");
			sqlMapper = new SqlSessionFactoryBuilder().build(reader);
			reader.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * @param depId
	 * @return
	 * @throws Exception
	 */
	public Collection<User> getUserBYDepId(String depId) throws Exception {
		Collection<User> list=new ArrayList<User>();
		
		SqlSession session = sqlMapper.openSession();
		
		try{
			list=session.selectList("me.duwl.selectDepStaff",depId);
//			session.commit();
		}finally{
			session.close();
		}
		return list;
		
	}
	public static void main(String[] args) {
		UserManager um =new UserManager();
		try {
			//System.out.println(um.getUserBYDepId("010101"));
			List<User> ulist=(List<User>) um.getUserBYDepId("010101");
			for(int i=0;i<ulist.size();i++) {
				System.out.println(ulist.get(i));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
